package gpc

import (
	"os"

	"gitee.com/hz2769514387/gpc/system"
)

// 单进程模式，建议在main函数第一行调用
// 调用示例: defer SingletonProcess("mutex name")()
func SingletonProcess(mutexName string) func() {
	namedLock := new(system.NamedLock)
	ok := namedLock.Lock(mutexName)
	if !ok {
		os.Exit(0)
	}
	return func() {
		namedLock.Unlock()
	}
}
